
last_time = 0
B = 0
ticks = 0
interrupt = 0

function interrupt()
	A = readA();
	if (A == 0) then
	B = readB();
	ticks = 0;
	last_time = ptime();
	else
		if (A == 1) then
		setC(ticks);
		ticks = 0;
		else
			if (A == 2) then
				interrupt = readB();
				end
			end
		end
	end
end

function update()
	if (B ~= 0) then
		if ( (1000*(ptime() - last_time)) > (60/B) ) then
			ticks = ticks + 1;
			last_time = ptime();
			if (interrupt ~= 0) then
				issueHWI(interrupt);
			end
		end 
	end
end